const jwt = require('jsonwebtoken')
let secret = 'xiaohe'
// 生产token
const generateToken = (id) => {

    let payload = { id, time: new Date() }

    let token = jwt.sign(payload, secret, { expiresIn: 60 * 60 * 24 * 120 })

    return token

}


// 解码
const verifyToken = (e) => {
    try {

        let payload = jwt.verify(e, secret)
        return payload
    } catch {
        return false
    }

}
module.exports = { generateToken, verifyToken }